#include <stdio.h>
#include <stdlib.h>
#include "serveur.h"
#include "requetes.h"

int main(int argc, char **argv)
{
    SOCKET sock, service;
    SOCKADDR_IN client;
    int tailleAdresse = sizeof(client);
    winstart();

    sock=debutConnexion();
    while (1){
        puts("attente de la connexion d'un client");
        if (-1 == ( service = accept(sock,(SOCKADDR *) &client, (socklen_t *) &tailleAdresse) ) )
        {
            perror("Erreur connexion client !!!");
            exit(EXIT_FAILURE);
        }

        //traitement des requetes
        if( -1 == traitementRequetes(service ) ){
            puts("fermé annormalement");
        }else{
            puts ("client connecté");
            closesocket(service);
        }
    }
    winstop();

    return EXIT_SUCCESS;
}

